/**
 * @param {number[]} arr
 * @param {number} k
 * @return {number[]}
*/
var getLeastNumbers = function(arr, k) {
  arr.sort((a, b) => a - b);
  return arr.slice(0, k);
};
let arr = [3,2,1], k = 2;
console.log(getLeastNumbers(arr, k));
arr = [0,1,2,1], k = 1;
console.log(getLeastNumbers(arr, k));
